#include "GameApp.h"

HGE* CGameApp::hge = NULL;
CGameView* CGameApp::m_pGameView = NULL;

CGameApp::CGameApp(void)
{
}

CGameApp::~CGameApp(void)
{
}

bool CGameApp::DoFrame()
{
	bool result = false;
	if(m_pGameView)
		result = m_pGameView->DoFrame();
	return result;
}

bool CGameApp::DoRender()
{
	hge->Gfx_BeginScene();
	hge->Gfx_Clear(0xffffffff);
	// to-do render
	bool result = false;
	if(m_pGameView)
		result = m_pGameView->DoRender();
	hge->Gfx_EndScene();
	return result;
}

void CGameApp::InitializeHGE()
{
	hge = hgeCreate(HGE_VERSION);

	if(hge)
	{
#ifdef _DEBUG
		hge->System_SetState(HGE_LOGFILE,LOGFILE);
#endif
		hge->System_SetState(HGE_SHOWSPLASH,false);
		hge->System_SetState(HGE_FRAMEFUNC,DoFrame);
		hge->System_SetState(HGE_RENDERFUNC,DoRender);
		hge->System_SetState(HGE_TITLE,"LotusLeaf");
		hge->System_SetState(HGE_USESOUND,false);
		hge->System_SetState(HGE_WINDOWED,true);
		hge->System_SetState(HGE_SCREENWIDTH,WINDOW_WIDTH);
		hge->System_SetState(HGE_SCREENHEIGHT,WINDOW_HEIGHT);
		hge->System_SetState(HGE_SCREENBPP,32);
		hge->System_SetState(HGE_ZBUFFER,true);
	}
}

void CGameApp::GameRun()
{
	if(hge && hge->System_Initiate())
	{
		m_pGameView = new CGameView(hge);
		m_pGameView->LoadMap("..\\..\\res\\LotusLeaf\\1.dat");
		hge->System_Start();
	}
	else
	{
		MessageBox(NULL,hge->System_GetErrorMessage(),"Error",MB_OK);
	}
}

void CGameApp::ReleaseHGE()
{
	if(hge)
	{
		hge->System_Shutdown();
		hge->Release();
	}
}